﻿using System;
using YhmOA.Model;
using System.Web.UI.WebControls;

namespace YhmOA.ManagerOA.User
{
    public partial class UserList : ManagerPage<ManagerOA_User_User>
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        #region GridView的行绑定事件
        protected void gvShow_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ManagerOA_User_User info = e.Row.DataItem as ManagerOA_User_User;
                ImageButton imgBtnUserState = e.Row.FindControl("imgBtnUserState") as ImageButton;
                if (imgBtnUserState != null)
                {
                    if (info.UserState == 0)
                    {
                        imgBtnUserState.ImageUrl = "~/Images/UserState_0.png";
                        imgBtnUserState.ToolTip = "禁用用户";
                    }
                    else
                    {
                        imgBtnUserState.ImageUrl = "~/Images/UserState_1.png";
                        imgBtnUserState.ToolTip = "活动用户";
                    }
                    imgBtnUserState.OnClientClick = imgBtnUserState.OnClientClick + "; __doPostBack('" + imgBtnUserState.UniqueID + "', '');return false;";
                    imgBtnUserState.CommandArgument = info.ID.ToString();
                }
            }
        }
        #endregion

        #region GridView的行内事件
        protected void gvShow_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
        {
            if (e.CommandName == "UserState")
            {
                ManagerOA_User_User info = this.Dal.GetModelByID(Convert.ToInt32(e.CommandArgument));
                info.UserState = info.UserState == 0 ? 1 : 0;
                this.Dal.Update(info, Convert.ToInt32(e.CommandArgument));
                this.Search();
            }
        }
        #endregion
    }
}